home *** CD-ROM | disk | FTP | other *** search
/ PC World 2007 June / PCWorld_2007-06_cd.bin / v cisle / tclock / tclocklight-040702-3.exe / source / property / pagecuckoo.c < prev    next >
C/C++ Source or Header  |  2004-01-18  |  6KB  |  246 lines

  1. /*-------------------------------------------------------------
  2.   pagecuckoo.c : "Cuckoo" page of properties
  3.   (C) Kazuto Sato 1997-2003
  4.   For the license, please read readme.txt.
  5.   
  6.   Written by Kazubon, Nanashi-san
  7. ---------------------------------------------------------------*/
  8.  
  9. #include "tcprop.h"
  10.  
  11. /* Globals */
  12.  
  13. BOOL CALLBACK PageCuckooProc(HWND hDlg, UINT message,
  14.     WPARAM wParam, LPARAM lParam);
  15.  
  16. /* Statics */
  17.  
  18. static void SendPSChanged(HWND hDlg);
  19. static void OnInit(HWND hDlg);
  20. static void OnApply(HWND hDlg);
  21. static void OnDestroy(HWND hDlg);
  22. static void OnCuckoo(HWND hDlg);
  23. static void OnBrowse(HWND hDlg);
  24. static void OnFileChange(HWND hDlg);
  25. static void OnTest(HWND hDlg);
  26.  
  27. static BOOL  m_bInit = FALSE;
  28. static BOOL  m_bChanged = FALSE;
  29.  
  30. static BOOL m_bPlaying = FALSE;
  31.  
  32. /*------------------------------------------------
  33.   Dialog procedure
  34. --------------------------------------------------*/
  35. BOOL CALLBACK PageCuckooProc(HWND hDlg, UINT message,
  36.     WPARAM wParam, LPARAM lParam)
  37. {
  38.     switch(message)
  39.     {
  40.         case WM_INITDIALOG:
  41.             OnInit(hDlg);
  42.             return TRUE;
  43.         case WM_COMMAND:
  44.         {
  45.             WORD id, code;
  46.             id = LOWORD(wParam); code = HIWORD(wParam);
  47.             switch(id)
  48.             {
  49.                 case IDC_CUCKOO:
  50.                     OnCuckoo(hDlg);
  51.                     break;
  52.                 case IDC_CUCKOOFILE:
  53.                     if(code == EN_CHANGE)
  54.                     {
  55.                         OnFileChange(hDlg);
  56.                         SendPSChanged(hDlg);
  57.                     }
  58.                     break;
  59.                 case IDC_CUCKOOBROWSE:
  60.                     OnBrowse(hDlg);
  61.                     OnFileChange(hDlg);
  62.                     SendPSChanged(hDlg);
  63.                     break;
  64.                 case IDC_CUCKOOREPEAT:
  65.                 case IDC_CUCKOOBLINK:
  66.                     SendPSChanged(hDlg);
  67.                     break;
  68.                 case IDC_CUCKOOTEST:
  69.                     OnTest(hDlg);
  70.                     break;
  71.             }
  72.             return TRUE;
  73.         }
  74.         case WM_NOTIFY:
  75.             switch(((NMHDR *)lParam)->code)
  76.             {
  77.                 case PSN_APPLY: OnApply(hDlg); break;
  78.                 case PSN_HELP: MyHelp(GetParent(hDlg), "Cuckoo"); break;
  79.             }
  80.             return TRUE;
  81.         case WM_DESTROY:
  82.             OnDestroy(hDlg);
  83.             break;
  84.         // playing sound ended
  85.         case MM_MCINOTIFY:
  86.         case MM_WOM_DONE:
  87.             if(message == MM_MCINOTIFY)
  88.                 OnMCINotify(hDlg, wParam, (LONG)lParam);
  89.             else
  90.                 StopFile();
  91.             m_bPlaying = FALSE;
  92.             SendDlgItemMessage(hDlg, IDC_CUCKOOTEST,
  93.                 BM_SETIMAGE, IMAGE_ICON, (LPARAM)g_hIconPlay);
  94.             return TRUE;
  95.     }
  96.     return FALSE;
  97. }
  98.  
  99. /*------------------------------------------------
  100.   notify parent window to enable "Apply" button
  101. --------------------------------------------------*/
  102. void SendPSChanged(HWND hDlg)
  103. {
  104.     if(m_bInit)
  105.     {
  106.         g_bApplyMain = TRUE;
  107.         m_bChanged = TRUE;
  108.         SendMessage(GetParent(hDlg), PSM_CHANGED, (WPARAM)(hDlg), 0);
  109.     }
  110. }
  111.  
  112. /*------------------------------------------------
  113.   initialize
  114. --------------------------------------------------*/
  115. void OnInit(HWND hDlg)
  116. {
  117.     char s[MAX_PATH];
  118.     
  119.     m_bInit = FALSE;
  120.     
  121.     // common/tclang.c
  122.     SetDialogLanguage(hDlg, "Cuckoo", g_hfontDialog);
  123.     
  124.     CheckDlgButton(hDlg, IDC_CUCKOO,
  125.         GetMyRegLong(NULL, "Jihou", FALSE));
  126.     GetMyRegStr(NULL, "JihouFile", s, MAX_PATH, "");
  127.     SetDlgItemText(hDlg, IDC_CUCKOOFILE, s);
  128.     CheckDlgButton(hDlg, IDC_CUCKOOREPEAT,
  129.         GetMyRegLong(NULL, "JihouRepeat", FALSE));
  130.     CheckDlgButton(hDlg, IDC_CUCKOOBLINK,
  131.         GetMyRegLong(NULL, "JihouBlink", FALSE));
  132.     
  133.     SendDlgItemMessage(hDlg, IDC_CUCKOOTEST, BM_SETIMAGE, IMAGE_ICON,
  134.         (LPARAM)g_hIconPlay);
  135.     
  136.     OnCuckoo(hDlg);
  137.     
  138.     m_bPlaying = FALSE;
  139.     
  140.     m_bInit = TRUE;
  141. }
  142.  
  143. /*------------------------------------------------
  144.    apply - save settings
  145. --------------------------------------------------*/
  146. void OnApply(HWND hDlg)
  147. {
  148.     char s[MAX_PATH];
  149.     
  150.     if(!m_bChanged) return;
  151.     m_bChanged = FALSE;
  152.     
  153.     SetMyRegLong(NULL, "Jihou",
  154.         IsDlgButtonChecked(hDlg, IDC_CUCKOO));
  155.     GetDlgItemText(hDlg, IDC_CUCKOOFILE, s, MAX_PATH);
  156.     SetMyRegStr(NULL, "JihouFile", s);
  157.     SetMyRegLong(NULL, "JihouRepeat",
  158.         IsDlgButtonChecked(hDlg, IDC_CUCKOOREPEAT));
  159.     SetMyRegLong(NULL, "JihouBlink",
  160.         IsDlgButtonChecked(hDlg, IDC_CUCKOOBLINK));
  161. }
  162.  
  163. /*------------------------------------------------
  164.   free memories associated with combo box.
  165. --------------------------------------------------*/
  166. void OnDestroy(HWND hDlg)
  167. {
  168.     if(m_bPlaying) StopFile(); m_bPlaying = FALSE;
  169. }
  170.  
  171. /*------------------------------------------------
  172.   "Cuckoo clock" checkbox
  173. --------------------------------------------------*/
  174. void OnCuckoo(HWND hDlg)
  175. {
  176.     HWND hwnd = GetDlgItem(hDlg, IDC_CUCKOO);
  177.     BOOL b = IsDlgButtonChecked(hDlg, IDC_CUCKOO);
  178.     
  179.     hwnd = GetNextWindow(hwnd, GW_HWNDNEXT);
  180.     while(hwnd)
  181.     {
  182.         EnableWindow(hwnd, b);
  183.         hwnd = GetNextWindow(hwnd, GW_HWNDNEXT);
  184.     }
  185.     if(b) OnFileChange(hDlg);
  186.     SendPSChanged(hDlg);
  187. }
  188.  
  189. /*------------------------------------------------
  190.   browse sound file
  191. --------------------------------------------------*/
  192. void OnBrowse(HWND hDlg)
  193. {
  194.     char deffile[MAX_PATH], fname[MAX_PATH];
  195.     
  196.     GetDlgItemText(hDlg, IDC_CUCKOOFILE, deffile, MAX_PATH);
  197.     
  198.     // common/soundselect.c
  199.     if(!BrowseSoundFile(g_hInst, hDlg, deffile, fname))
  200.         return;
  201.     
  202.     SetDlgItemText(hDlg, IDC_CUCKOOFILE, fname);
  203.     PostMessage(hDlg, WM_NEXTDLGCTL, 1, FALSE);
  204. }
  205.  
  206. /*------------------------------------------------
  207.    file name changed - enable/disable controls
  208. --------------------------------------------------*/
  209. void OnFileChange(HWND hDlg)
  210. {
  211.     char fname[MAX_PATH];
  212.     
  213.     GetDlgItemText(hDlg, IDC_CUCKOOFILE, fname, MAX_PATH);
  214.     
  215.     EnableDlgItem(hDlg, IDC_CUCKOOREPEAT, IsSoundFile(fname));
  216. }
  217.  
  218. /*------------------------------------------------
  219.   test sound
  220. --------------------------------------------------*/
  221. void OnTest(HWND hDlg)
  222. {
  223.     char fname[MAX_PATH];
  224.     
  225.     GetDlgItemText(hDlg, IDC_CUCKOOFILE, fname, MAX_PATH);
  226.     if(fname[0] == 0) return;
  227.     
  228.     if((HICON)SendDlgItemMessage(hDlg, IDC_CUCKOOTEST,
  229.         BM_GETIMAGE, IMAGE_ICON, 0) == g_hIconPlay)
  230.     {
  231.         if(PlayFile(hDlg, fname, 0))
  232.         {
  233.             SendDlgItemMessage(hDlg, IDC_CUCKOOTEST,
  234.                 BM_SETIMAGE, IMAGE_ICON, (LPARAM)g_hIconStop);
  235.             InvalidateRect(GetDlgItem(hDlg, IDC_CUCKOOTEST), NULL, FALSE);
  236.             m_bPlaying = TRUE;
  237.         }
  238.     }
  239.     else
  240.     {
  241.         StopFile();
  242.         m_bPlaying = FALSE;
  243.     }
  244. }
  245.  
  246.